package com.itheima.controller;

import com.itheima.anno.Log;
import com.itheima.pojo.*;

import com.itheima.service.ClazzService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j//记录日志
@RequestMapping("/clazzs")
@RestController//@Controller+@ResponseBody
public class ClazzController {

    @Autowired
    private ClazzService clazzService;

    @GetMapping("/list")
    public Result list(){
        log.info("查询所有员工信息");
        List<Clazz> clazzList = clazzService.list();
        return Result.success(clazzList);
    }

    @GetMapping
    public Result list(ClazzQueryParam clazzQueryParam){;
        log.info("查询条件:{}",clazzQueryParam);
        PageResult<Clazz> pageResult = clazzService.page(clazzQueryParam);
        return Result.success(pageResult);
    }

    @Log
    @DeleteMapping("/{id}")
    public Result delete(@PathVariable Integer id){
        log.info("删除员工：{}", id);
        clazzService.delete(id);
        return Result.success();
    }
    @PostMapping
    @Log
    public Result add(@RequestBody Clazz clazz){
        log.info("新增员工：{}",clazz);
        clazzService.save(clazz);
        return Result.success();
    }

    @GetMapping("/{id}")
    public Result get(@PathVariable Integer id){
        log.info("查询员工：{}", id);
        Clazz clazz =  clazzService.getInfo(id);
        return Result.success(clazz);
    }
    @PutMapping
    @Log
    public Result update(@RequestBody Clazz clazz){
        log.info("修改员工：{}", clazz);
        clazzService.update(clazz);
        return Result.success();
    }
}
